package com.huhu.service;

import com.huhu.dao.UserDao;
import com.huhu.entity.User;
import com.huhu.service.inter.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;

import java.util.concurrent.TimeUnit;

/**
 * Created by xuyi on 2017/2/2.
 */
@Service
public class TestServiceImpl implements TestService {

    @Autowired
    private UserDao userDao;

    @Override
    public int dontSayHello_2(String hello) {

        User user = userDao.selectByPrimaryKey(1);
        System.out.println(user.getSalt());
        return 1;
    }

    @Transactional(isolation = Isolation.READ_COMMITTED)
    @Override
    public int dontSayHello(String hello) {

        User user = new User();
        user.setUserId(1);
        user.setSalt("testTransactional");
        int updateByPrimaryKeySelective = userDao.updateByPrimaryKeySelective(user);
        try {
            TimeUnit.SECONDS.sleep(20L);
        } catch (Exception e) {
            e.printStackTrace();
        }
//        int i = 1 / 0;

        return updateByPrimaryKeySelective;
    }
}
